home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gtlayout.lha / Source / LTP_DetermineSize.c < prev    next >
C/C++ Source or Header  |  1998-09-09  |  26KB  |  1,076 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. LONG
  17. LTP_GetPickerWidth(
  18.     LONG    fontHeight,
  19.     LONG    aspectX,
  20.     LONG    aspectY)
  21. {
  22.     LONG margin,width;
  23.  
  24.     width = (fontHeight * aspectY) / aspectX;
  25.  
  26.     if(width < 8)
  27.         width = 8;
  28.  
  29.     margin = 2 + (width + 15) / 16;
  30.  
  31.     return((LONG)(margin + (((115 * width) / 150) & ~1) + 1 + margin));
  32. }
  33.  
  34. LONG
  35. LTP_GetPickerSize(LayoutHandle *Handle)
  36. {
  37.     return(LTP_GetPickerWidth(Handle->TextAttr->ta_YSize,Handle->AspectX,Handle->AspectY));
  38. }
  39.  
  40. VOID
  41. LTP_DetermineSize(LayoutHandle *Handle,ObjectNode *Node)
  42. {
  43.     if(!Handle->Failed)
  44.     {
  45.         LONG i,Len,Width,Max,Plus;
  46.  
  47.         if(Node->Label)
  48.         {
  49.             LONG LabelWidth = LT_LabelWidth(Handle,Node->Label);
  50.  
  51.             if(Node->LabelChars * Handle->GlyphWidth > LabelWidth)
  52.                 LabelWidth = Node->LabelChars * Handle->GlyphWidth;
  53.  
  54.             Node->LabelWidth = LabelWidth;
  55.         }
  56.         else
  57.             Node->LabelWidth = 0;
  58.  
  59.         switch(Node->Type)
  60.         {
  61.             #ifdef DO_BOOPSI_KIND
  62.             {
  63.                 case BOOPSI_KIND:
  64.  
  65.                     if(Node->Special.BOOPSI.ExactWidth)
  66.                         Node->Width = Node->Special.BOOPSI.ExactWidth;
  67.                     else
  68.                         Node->Width = Node->Chars * Handle->GlyphWidth;
  69.  
  70.                     if(Node->Special.BOOPSI.ExactHeight)
  71.                         Node->Height = Node->Special.BOOPSI.ExactHeight;
  72.                     else
  73.                         Node->Height = Node->Lines * Handle->GlyphHeight;
  74.  
  75.                     if(Node->Special.BOOPSI.RelFontHeight)
  76.                         Node->Height = Handle->GlyphHeight + Node->Special.BOOPSI.RelFontHeight;
  77.  
  78.                     break;
  79.             }
  80.             #endif    /* DO_BOOPSI_KIND */
  81.  
  82.             #ifdef DO_LEVEL_KIND
  83.             {
  84.                 case LEVEL_KIND:
  85.  
  86.                     if(Node->Special.Level.Freedom == FREEHORIZ)
  87.                     {
  88.                         Node->Width        = 6 + Node->Chars * Handle->GlyphWidth + 6;
  89.                         Node->Height    = LTP_QuerySliderSize(Handle->DrawInfo,Handle->GlyphHeight,FREEHORIZ,Node->Special.Level.Ticks);
  90.                     }
  91.                     else
  92.                     {
  93.                         Node->Height    = Node->Lines * Handle->GlyphHeight;
  94.                         Node->Width        = LTP_QuerySliderSize(Handle->DrawInfo,Handle->GlyphHeight,FREEVERT,Node->Special.Level.Ticks);
  95.                     }
  96.  
  97.                     if(Node->DefaultSize && Node->Height < 3 + Handle->GlyphHeight + 3)
  98.                         Node->Height = 3 + Handle->GlyphHeight + 3;
  99.  
  100.                     LTP_GetStorage(Node);
  101.  
  102.                     if(Node->Current > Node->Max)
  103.                     {
  104.                         Node->Current = Node->Max;
  105.  
  106.                         LTP_PutStorage(Node);
  107.                     }
  108.  
  109.                     if(Node->Current < Node->Min)
  110.                     {
  111.                         Node->Current = Node->Min;
  112.  
  113.                         LTP_PutStorage(Node);
  114.                     }
  115.  
  116.                     if(!Node->Special.Level.MaxLevelWidth || Handle->Rescaled)
  117.                     {
  118.                         LTP_LevelWidth(Handle,Node->Special.Level.LevelFormat,Node->Special.Level.DispFunc,Node->Min,Node->Max,&Node->Special.Level.MaxLevelWidth,NULL,Node->Special.Level.FullLevelCheck);
  119.  
  120.                         Node->Special.Level.MaxLevelWidth += TextLength(&Handle->RPort," ",1);
  121.                     }
  122.  
  123.                     if(!Node->Special.Level.Plus)
  124.                         Node->Special.Level.Plus = Node->Min;
  125.  
  126.                     if(Node->LabelChars * Handle->GlyphWidth > Node->LabelWidth)
  127.                         Node->LabelWidth = Node->LabelChars * Handle->GlyphWidth;
  128.  
  129.                     if(Node->Special.Level.LevelPlace == PLACETEXT_LEFT &&
  130.                        Node->LabelPlace == PLACE_LEFT &&
  131.                        Node->Special.Level.LevelFormat != NULL)
  132.                     {
  133.                         Node->LabelWidth += Node->Special.Level.MaxLevelWidth;
  134.                     }
  135.  
  136.                     break;
  137.             }
  138.             #endif    /* DO_LEVEL_KIND */
  139.  
  140.             case GROUP_KIND:
  141.  
  142.                 LTP_LayoutGroup(Handle,Node);
  143.  
  144.                 break;
  145.  
  146.             case XBAR_KIND:
  147.  
  148.                 Node->Width        = Handle->GlyphWidth;
  149.                 Node->Height    = 6;
  150.  
  151.                 break;
  152.  
  153.             case YBAR_KIND:
  154.  
  155.                 Node->Width        = 6;
  156.                 Node->Height    = Handle->GlyphHeight;
  157.  
  158.                 if(Node->DefaultSize)
  159.                     Node->Height = 3 + Handle->GlyphHeight + 3;
  160.  
  161.                 break;
  162.  
  163.             case IMAGE_KIND:
  164.  
  165.                 if(Node->Special.Image.Image != NULL)
  166.                 {
  167.                     Node->Width        = Node->Special.Image.Image->Width;
  168.                     Node->Height    = Node->Special.Image.Image->Height;
  169.                 }
  170.                 else if (Node->Special.Image.BitMap != NULL)
  171.                 {
  172.                     Node->Width        = Node->Special.Image.BitMapWidth;
  173.                     Node->Height    = Node->Special.Image.BitMapHeight;
  174.                 }
  175.                 else
  176.                 {
  177.                     Handle->Failed = TRUE;
  178.                 }
  179.  
  180.                 break;
  181.  
  182.             case FRAME_KIND:
  183.             {
  184.                 LONG Width    = Node->Special.Frame.InnerWidth;
  185.                 LONG Height    = Node->Special.Frame.InnerHeight;
  186.  
  187.                 if(Node->Special.Frame.PlusWidth > 0 || Node->Special.Frame.PlusHeight > 0)
  188.                 {
  189.                     Width    += Node->Special.Frame.PlusWidth * Handle->GlyphWidth;
  190.                     Height    += Node->Special.Frame.PlusHeight * Handle->GlyphHeight;
  191.                 }
  192.  
  193.                 if(Node->Special.Frame.DrawBox)
  194.                 {
  195.                     Node->Width        = 4 + Width + 4;
  196.                     Node->Height    = 2 + Height + 2;
  197.                 }
  198.                 else
  199.                 {
  200.                     Node->Width        = Width;
  201.                     Node->Height    = Height;
  202.                 }
  203.  
  204.                 break;
  205.             }
  206.  
  207.             case BOX_KIND:
  208.  
  209.                 Node->LabelWidth = 0;
  210.  
  211.                 if(Node->Special.Box.Labels)
  212.                 {
  213.                     for(i = 0 ; i < Node->Lines ; i++)
  214.                     {
  215.                         if((Width = TextLength(&Handle->RPort,Node->Special.Box.Labels[i],strlen(Node->Special.Box.Labels[i]))) > Node->LabelWidth)
  216.                             Node->LabelWidth = Width;
  217.                     }
  218.                 }
  219.  
  220.                 if(Node->LabelChars)
  221.                 {
  222.                     if(Node->LabelChars * Handle->GlyphWidth > Node->LabelWidth)
  223.                         Node->LabelWidth = Node->LabelChars * Handle->GlyphWidth;
  224.                     else
  225.                         Node->LabelWidth = ((Node->LabelWidth + Node->LabelChars - 1) / Node->LabelChars) * Node->LabelChars;
  226.                 }
  227.  
  228.                 Max = Node->Chars;
  229.  
  230.                 if(Node->Special.Box.Lines)
  231.                 {
  232.                     LONG MaxWidth = 0;
  233.  
  234.                     for(i = 0 ; i < Node->Lines ; i++)
  235.                     {
  236.                         if(Node->Special.Box.Lines[i])
  237.                         {
  238.                             if(Len = strlen(Node->Special.Box.Lines[i]))
  239.                             {
  240.                                 if((Width = TextLength(&Handle->RPort,Node->Special.Box.Lines[i],Len)) > MaxWidth)
  241.                                     MaxWidth = Width;
  242.                             }
  243.                         }
  244.                     }
  245.  
  246.                     if(Max < (MaxWidth + Handle->GlyphWidth - 1) / Handle->GlyphWidth)
  247.                         Max = (MaxWidth + Handle->GlyphWidth - 1) / Handle->GlyphWidth;
  248.                 }
  249.  
  250.                 Node->Height    = 2 + Node->Lines * (Handle->GlyphHeight + Node->Special.Box.Spacing) + 2;
  251.                 Node->Width        = 4 + Max * Handle->GlyphWidth + 4;
  252.  
  253.                 if(Node->DefaultSize)
  254.                     Node->Height = 3 + Node->Lines * (Handle->GlyphHeight + Node->Special.Box.Spacing) + 3;
  255.  
  256.                 Node->Height -= Node->Special.Box.Spacing;
  257.  
  258.                 break;
  259.  
  260.             case BLANK_KIND:
  261.  
  262.                 Node->Width            = Handle->GlyphWidth * max(1,Node->Chars);
  263.                 Node->Height        = Handle->GlyphHeight;
  264.                 Node->Label            = "";
  265.                 Node->LabelWidth    = 0;
  266.                 Node->LabelPlace    = PLACE_IN;
  267.  
  268.                 if(Node->DefaultSize)
  269.                     Node->Height = 3 + Handle->GlyphHeight + 3;
  270.  
  271.                 break;
  272.  
  273.             case BUTTON_KIND:
  274.  
  275.                 if(!Node->Special.Button.Lines && Node->Label)
  276.                 {
  277.                     LONG i,Len = strlen(Node->Label),Count = 0;
  278.  
  279.                     for(i = 0 ; i < Len ; i++)
  280.                     {
  281.                         if(Node->Label[i] == '\n')
  282.                             Count++;
  283.                     }
  284.  
  285.                     if(Count)
  286.                     {
  287.                         STRPTR *Lines;
  288.  
  289.                         if(Lines = (STRPTR *)LTP_Alloc(Handle,(Count + 2) * sizeof(STRPTR) + Len + 1))
  290.                         {
  291.                             STRPTR String = (STRPTR)(&Lines[Count + 2]);
  292.  
  293.                             strcpy(String,Node->Label);
  294.  
  295.                             Node->Special.Button.Lines = Lines;
  296.  
  297.                             if(Node->Special.Button.KeyStroke)
  298.                                 Node->Special.Button.KeyStroke = &String[((ULONG)Node->Special.Button.KeyStroke) - ((ULONG)Node->Label)];
  299.  
  300.                             do
  301.                             {
  302.                                 *Lines++ = String;
  303.  
  304.                                 for(i = 0 ; String[i] ; i++)
  305.                                 {
  306.                                     if(String[i] == '\n')
  307.                                     {
  308.                                         String[i] = 0;
  309.  
  310.                                         String = &String[i + 1];
  311.  
  312.                                         break;
  313.                                     }
  314.                                 }
  315.                             }
  316.                             while(Count--);
  317.                         }
  318.                         else
  319.                             break;
  320.  
  321.                         LTP_ReplaceLabelShortcut(Handle,Node);
  322.                     }
  323.                 }
  324.  
  325.                 if(Node->Special.Button.Lines)
  326.                 {
  327.                     STRPTR    *Index = Node->Special.Button.Lines;
  328.                     LONG     Count = 0,Width,MaxWidth = 0,Height;
  329.  
  330.                     while(*Index)
  331.                     {
  332.                         Count++;
  333.  
  334.                         if((Width = LT_LabelWidth(Handle,*Index)) > MaxWidth)
  335.                             MaxWidth = Width;
  336.  
  337.                         Index++;
  338.                     }
  339.  
  340.                     Node->Special.Button.LineCount = Count;
  341.  
  342.                     if(Node->Chars * Handle->GlyphWidth > MaxWidth)
  343.                         MaxWidth = Node->Chars * Handle->GlyphWidth;
  344.  
  345.                     if(Node->Lines > Count)
  346.                         Count = Node->Lines;
  347.  
  348.                     Height = Count * Handle->GlyphHeight;
  349.  
  350.                     if(Node->Special.Button.ExtraFat)
  351.                     {
  352.                         Node->Width        = 6 + Handle->GlyphWidth + MaxWidth + Handle->GlyphWidth + 6;
  353.                         Node->Height    = 2 + (2 * Height + Handle->GlyphHeight) / 2 + 2;
  354.                     }
  355.                     else
  356.                     {
  357.                         if(Node->Special.Button.Smaller)
  358.                         {
  359.                             Node->Width        = 4 + MaxWidt